package com.yloveg.base;

import java.beans.PropertyEditorSupport; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import org.apache.commons.lang.StringUtils; 


public class DateEditor extends PropertyEditorSupport { 
	@Override 
	public void setAsText(String text) throws IllegalArgumentException { 
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		Date date = null; 
		if(StringUtils.isBlank(text)){ 
			return; 
		} 
		try { 
			date = format.parse(text); 
		} catch (ParseException e) { 
			format = new SimpleDateFormat("yyyy-MM-dd"); 
			try { 
				date = format.parse(text); 
			} catch (ParseException e1) { 
				e1.printStackTrace(); 
			} 
		} 
		setValue(date); 
	} 
} 